<?php
App::import('Vendor', 'BeanStalk', array('file' => 'BeanStalk.class.php'));
class QueueComponent extends Object {

	var $connection = null;
	var $job = null;
	var $command = null;
	
	function initialize() {
	    $this->connection = BeanStalk::open(array(
	        'servers'       => array( '127.0.0.1:11300' ),
	        'select'        => 'random peek',
			'peek_usleep'	=> 1000000,
			'auto_unyaml'	=> false
	    ));
	}

	function use_tube($tube) {
		$this->connection->use_tube($tube);
	}

	function put($priority, $delay, $ttr, $job, $tube = null) {
	    $this->connection->put($priority, $delay, $ttr, $job, $tube);
	}

	function reserve(){
		$this->job = $this->connection->reserve();
	}

	function get(){
		$this->command = $this->job->get();
	}

	function delete(){
		BeanStalk::delete($this->job);
	}

}
?>